<?php
session_start();
require "../../../global.php";
require RootDir."/"."inc/config.php";
require RootDir."/"."inc/Function.Libary.php";
require RootDir."/"."inc/Uifunction.php";
require RootDir."/".$SystemConest[1]."/system/Config.php";
require RootDir."/".$SystemConest[1]."/UIFunction/adminClass.php";
require RootDir."/".$SystemConest[1]."/system/menusys/function.php";
require RootDir."/".$SystemConest[1]."/system/classsys/function.php";
require RootDir."/".$SystemConest[1]."/system/log/addlog.php";

FunPostGetFilter(2);//过滤非法信息
$PMID=$_REQUEST["PMID"];
$mydb=new YYBDB();
$TableName=$mydb->getTableName($MenuId);
CheckRule($MenuId,$mydb,$TableName,"Add");//检查登陆权限
$FormConfig1=GetFormConfig($mydb,$MenuId);


$sql="select ".$SystemTablename[2]."10 from ".DQ.$SystemTablename[2]." where ".$SystemTablename[2]."0=".$MenuId;
$rsc=$mydb->db_query($sql);
if($rs=$mydb->db_fetch_array($rsc)){
	$Configother=explode(",",$rs[$SystemTablename[2]."10"]);
	
}


if(strlen($FormConfig1)<1) die;
$ArrFormConfig=explode(",",$FormConfig1);
$configarr=array();
$i=0;
foreach($ArrFormConfig as $k=>$v)
{
	$arr=explode("|",$v);
	$configarr[$i]=$arr;
	$i++;
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增保存</title>
<link href="../../Inc/Css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?
$PMID = $_REQUEST["PMID"];
$OwerID=$_REQUEST["OwerID"];


if(strlen($MenuId)<1)
{
	$MenuId=-1;
}

//权限控制
CheckRule($MenuId,$mydb,$TableName,"Add");


$FieldCount=GetTableFieldCount($mydb,$TableName);
$myFields=array();

for($i=1;$i<$FieldCount;$i++)
{
	if($_REQUEST["FieldName_".$i]!="")
	{
		if($_REQUEST["FieldName_".$i."_Min"]!="")
		{
			$temp="";
			$temp=$_REQUEST["st".$_REQUEST["FieldName_".$i."_Min"]];//当是无限级下拉菜单时
			if($temp!="")
			{
				$myFields[$i]=$temp;
			}
			else
			{
				$myFields[$i]=($_REQUEST["FieldName_".$i."_Min"]);
			}
		}
		else
		{
			$tempqwe=$_REQUEST["FieldName_".$i.""];
			if(is_array($tempqwe))
			{
				foreach($tempqwe as $t)
				{
					$myFields[$i]=$myFields[$i].$t.",";
				}
				$myFields[$i]=substr($myFields[$i],0,-1);
			}
			else
			{
				$myFields[$i]=$tempqwe;
				
			}
			//当是数字型时，转化为数字
			if($configarr[$i]["1"]=="8")
			{
				$myFields[$i]=strtotime($myFields[$i]);
			}
			
			unset($tempqwe);
			
		}
	}
	else
	{
		
		if($_REQUEST["FieldName_".$i."_class"]!="")
		{
			$myFields[$i]=mysql_real_escape_string($_REQUEST["FieldName_".$i."_class"]);
		}
		
	}
}
$MenuIdAt=$mydb->getMenuIdNum($MenuId);//MenuId所在字段
if($MenuIdAt>0) $myFields[$MenuIdAt]=$MenuId;


$mydb->TableName=$TableName;
$mydb->ArrFields=$myFields;
$mydb->Add();
//========================================================若有模板选项，生成静态文件件
$temp1="";
$turngotourl=$Configother[6];
if(strlen($turngotourl)>7){
	$turngotourl=str_replace("{MenuId}",$MenuId,$turngotourl);
	$turngotourl=str_replace("{PMID}",$PMID,$turngotourl);
	$turngotourl=str_replace("@",$ID,$turngotourl);
}
else{
	$turngotourl="/".$SystemConest[1]."/system/".$TableName."/Index.php?MenuId=$MenuId&PMID=". $_REQUEST["PMID"]."&CurrPage=" .$_REQUEST["CurrPage"].""	;
}
	if($mydb->Returns >0)
	{
		addlog($mydb,$_SESSION["Login"][1],"添加"+$TableName."记录".$MenuId);//添加日志
		MessgBox("/".$SystemConest[1]."/Iamges/Right.jpg","操作成功！$temp1",$turngotourl);
	}
	else
	{
		MessgBox("/".$SystemConest[1]."/Iamges/Error.jpg","操作失败！$temp1",$turngotourl);
	}
?>

</body>
</html>
